 /**
 * Description: 盘点明细报表
 * @author:Hunter
 * @since:1.0.0
 *
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2018-04-08   Hunter       1.0.0     Initial
 */
package com.metro.paperless.report.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageInfo;
import com.metro.core.annotation.BusinessDesc;
import com.metro.core.excel.JxlsView;
import com.metro.core.page.Page;
import com.metro.core.vo.JsonResult;
import com.metro.core.vo.QueryParams;
import com.metro.core.vo.ResultCode;
import com.metro.paperless.common.beans.constant.DicTypeEnum;
import com.metro.paperless.common.beans.constant.JxlsTemplateEnum;
import com.metro.paperless.common.utils.DicUtil;
import com.metro.paperless.report.beans.vo.ReportCheck;
import com.metro.paperless.report.service.inf.IReportCheckService;
import com.metro.paperless.web.controller.BaseController;
 /**
 * 盘点明细报表<br>
 *
 * @author:jacky
 * @since:1.0.0
 * @version [1.0.0, 2018-04-11]
 */
@Controller
@RequestMapping("/reportCheck")
public class ReportCheckController extends BaseController {
    //菜单编码
    private static final String menuCode = "REPORT_CHECK";
    //模块描述
    private static final String MODULE_DESC = "盘点明细报表";
    @Autowired
    private IReportCheckService reportCheckService;
   
    protected String getViewDir() {
        return "report/";
    }
    
    /**
     * 盘点明细报表
     * 
     * @param bizmaterialsmanage 盘点明细报表
     * @param page 分页配置
     * @return 结果视图
     * @author Hunter
     * @since [1.0.0]
     * @version [1.0.0, 2018-04-08]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "盘点明细")
    @RequiresPermissions(menuCode + ":view")
    @SuppressWarnings("all")
    @RequestMapping(value = "list", method = {RequestMethod.GET,RequestMethod.POST})
    public ModelAndView list(ReportCheck reportCheck) {
        ModelAndView mav = new ModelAndView();
        try {
            mav.setViewName(getView("reportCheck_list"));
            mav.addObject("searchEntity", reportCheck);
        } catch (Exception ex) {
            log.error("查询盘点明细出错", ex);
            mav.addObject("ex", ex);
            mav.setViewName("/commons/error/error");
        }
        return mav;
    }

    /**
     * 查询盘点明细
     *
     * @param bizmaterialsmanage 盘点明细页面表单对象
     * @param page 分页配置
     * @return 结果视图
     * @author Hunter
     * @since [1.0.0]
     * @version [1.0.0, 2018-04-08]
     */
    @BusinessDesc(ModuleDesc = MODULE_DESC, MethodDesc = "盘点明细")
    @RequiresPermissions(menuCode + ":view")
    @SuppressWarnings("all")
    @RequestMapping(value = "dolist", method = {RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public JsonResult dolist(ReportCheck reportCheck, Page page, QueryParams<ReportCheck> queryParams) {
        JsonResult jr = new JsonResult();
        
        try {
            queryParams.setPaging(page);
            queryParams.setEntity(reportCheck);
            PageInfo<ReportCheck> pageInfo = reportCheckService.queryForPage(queryParams);
            jr.setData(pageInfo);
            jr.setResult(ResultCode.SUCCESS);
        } catch (Exception ex){
            log.error("查询出入库明细出错",ex);
            jr.setResult(ResultCode.ERROR);
        }
        return jr;
    }

    /**
     * 导出
     * @return
     */
    @RequestMapping(value = "export", method = RequestMethod.POST)
    public ModelAndView export(ReportCheck entity) {
    	/*String name = entity.getOrgName();
        if(name !=null && name != "") {
        	entity.setOrgId(Long.parseLong(name));
        }*/
        List<ReportCheck> list = reportCheckService.queryForList(entity);
        return new ModelAndView(new JxlsView(JxlsTemplateEnum.CHECK, list));
    }

}
